package com.alibaba.controller;

import com.alibaba.model.entity.Product;
import com.alibaba.model.param.ProductParam;
import com.alibaba.service.ProductService;
import com.alibaba.utils.Result;
import jakarta.annotation.Resource;
import lombok.val;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author ZhouYaDong
 * @date 2025/9/26
 * @description
 */
@RestController
@RequestMapping("/products")
public class ProductController {

    @Resource
    private ProductService productService;

    @PostMapping("/updateProduct")
    public Result<String> updateProduct(@RequestBody @Validated ProductParam productParam) {
        // 将productParam赋值给Product
        val product = new Product();
        BeanUtils.copyProperties(productParam, product);
        val b = productService.updateProduct(product);
        if (b) {
            return Result.success("商品信息更新成功");
        } else {
            return Result.failure("商品信息更新失败");
        }
    }

}
